<link type="text/css" rel="stylesheet" href="<?php echo get_component_static_path(); ?>aieditor/static/style.css">
<script type="module">
    import {
        AiEditor
    } from '/component/element/aieditor/static/index.js'
    var aiEditor = new AiEditor({
        element: "#<?php echo $name ?>_editor",
        placeholder: "点击输入内容...",
        theme: "light",
        content: '',
        onChange: (aiEditor) => {
            $('#<?php echo $name ?>').text(aiEditor.getHtml());
        },
        image: {
            uploadUrl: '/element/aieditor/Index/upload?token=<?php echo element_safe_token('ueconfig'); ?>',
            uploadFormName: "image", //上传时的文件表单名称 

            uploaderEvent: {
                onUploadBefore: (file, uploadUrl, headers) => {

                },
                onSuccess: (file, response) => {
                    //监听图片上传成功
                    //注意：
                    // 1、如果此方法返回 false，则图片不会被插入到编辑器
                    // 2、可以在这里返回一个新的 json 给编辑器
                },
                onFailed: (file, response) => {

                },
                onError: (file, error) => {

                },
            },
        },

        <?php if ($editorconfig['model']) {
        ?>

            ai: {
                models: {
                    <?php echo $editorconfig['model'] ?>: {
                        appId: "<?php echo $editorconfig['appId'] ?>",
                        apiKey: "<?php echo $editorconfig['apiKey'] ?>",
                        apiSecret: "<?php echo $editorconfig['apiSecret'] ?>",
                        version: '<?php echo $editorconfig['version'] ?>'
                    }
                },
                bubblePanelEnable: true,
                bubblePanelModel: "auto",
            },
        <?php
        } ?>

    })

    aiEditor.insert(`<?php echo isset($value) ? $value  : '' ?>`);
</script>

<div id="<?php echo $name ?>_editor" style="height: 550px; "></div>
<textarea id="<?php echo $name ?>" name="<?php echo $name ?>" style="display:none"><?php echo isset($value) ? $value : '' ?></textarea>